// params = null  传参就使用传入的参数，不传参就是null
module.exports = (sql, params = null) => {
    const mysql = require("mysql");
    const conn = mysql.createConnection({
        host: "localhost",
        user: "root",
        password: "root",
        database: "school",
    });
    conn.connect();
    return new Promise((resolve, reject) => {
        // 执行你的异步代码，把成功的结果交给resolve，把失败的结果交给reject
        // conn.query(sql, params, callback);
        conn.query(sql, params, (err, result) => {
            err ? reject(err) : resolve(result);
        });
        conn.end();
    }).catch((err) => console.log(err.message));
};

// module.exports = abcd;